﻿
#include <iostream>
#include <GLBBuilder/GLBBuilder.hpp>

using namespace GLBBuilderLib;

int main()
{
    GLBBuilder Builder;

    GLBMeshData Mesh;
    Mesh.Name = "Cube";
    
    vec3 P0 = vec3(-1, 1, 1) * 0.5f;
    vec3 P1 = vec3(1, 1, 1) * 0.5f;
    vec3 P2 = vec3(-1, 1, -1) * 0.5f;
    vec3 P3 = vec3(1, 1, -1) * 0.5f;
    vec3 P4 = vec3(-1, -1, 1) * 0.5f;
    vec3 P5 = vec3(1, -1, 1) * 0.5f;
    vec3 P6 = vec3(-1, -1, -1) * 0.5f;
    vec3 P7 = vec3(1, -1, -1) * 0.5f;

    Mesh.Positions =
    {
        P0, P1, P2, P3,
        P5, P4, P7, P6,
        P3, P1, P7, P5,
        P0, P2, P4, P6,
        P2, P3, P6, P7,
        P1, P0, P5, P4,
    };
    Mesh.Normals =
    {
        vec3(1, 0, 0),  vec3(1, 0, 0),  vec3(1, 0, 0),  vec3(1, 0, 0),
        vec3(-1, 0, 0), vec3(-1, 0, 0), vec3(-1, 0, 0), vec3(-1, 0, 0),
        vec3(0, 1, 0),  vec3(0, 1, 0),  vec3(0, 1, 0),  vec3(0, 1, 0),
        vec3(0, -1, 0), vec3(0, -1, 0), vec3(0, -1, 0), vec3(0, -1, 0),
        vec3(0, 0, 1),  vec3(0, 0, 1),  vec3(0, 0, 1),  vec3(0, 0, 1),
        vec3(0, 0, -1), vec3(0, 0, -1), vec3(0, 0, -1), vec3(0, 0, -1)
    };
    Mesh.TexCoords =
    {
        vec2(0, 0), vec2(1, 0), vec2(0, 1), vec2(1, 1),
        vec2(0, 0), vec2(1, 0), vec2(0, 1), vec2(1, 1),
        vec2(0, 0), vec2(1, 0), vec2(0, 1), vec2(1, 1),
        vec2(0, 0), vec2(1, 0), vec2(0, 1), vec2(1, 1),
        vec2(0, 0), vec2(1, 0), vec2(0, 1), vec2(1, 1),
        vec2(0, 0), vec2(1, 0), vec2(0, 1), vec2(1, 1),
    };

    Builder.AddMaterial("White");

    auto Subset = GLBMeshSubsetData();
    Subset.Material = "White";
    Subset.TriangleIndices =
    {
         0, 1, 2, 1, 3, 2,
         4, 5, 6, 5, 7, 6,
         8, 9,10, 9,11,10,
        12,13,14,13,15,14,
        16,17,18,17,19,18,
        20,21,22,21,23,22,
    };
    Mesh.Subsets.push_back(Subset);
    
    auto Nodes = std::unordered_set<size_t>();
    Nodes.insert(Builder.AddNode(Builder.AddMesh(Mesh), std::vector<size_t>{}, vec3(0), quat(1, 0, 0, 0), vec3(1, 1, 1), "Cube"));

    Builder.AddScene("DefaultScene", Nodes);
    Builder.SaveGLB("test.glb", false);
    Builder.SaveGLTF("test.gltf", "test.bin");
    return 0;
}
